home *** CD-ROM | disk | FTP | other *** search
- #ifndef lint
- static char rcsid[] = "$Header: xboard.c,v 1.6 87/05/19 17:21:01 schoch Exp $";
- #endif
-
- #include "externs.h"
-
- static deltax, deltay;
- static Pixmap shadow;
- static int frompos;
- static bool realmove;
-
- startmove(pos, x, y)
- {
-
- if (pos < 0)
- return;
- if (pos >= 100) {
- fprintf(stderr, "Help! pos out of range.\n");
- return;
- }
- if (dead || resign || (drawok[BLACK] && drawok[WHITE])) {
- message("The game is over!", TOMOVE);
- return;
- }
- if (whose[pos] == OFFBOARD) {
- int myx;
-
- if (ourcolor == WHITE && (y < 64*8+TOPSPACE || y > 64*8+TOPSPACE+64))
- return;
- if (ourcolor == BLACK && !reverse &&
- (y < TOPSPACE-64 || y > TOPSPACE))
- return;
- if (ourcolor == BLACK && reverse &&
- (y < 64*8+TOPSPACE || y > 64*8+TOPSPACE+64))
- return;
- if (x < 0 || x > 8*64)
- return;
- myx = x - 16;
- if (myx < 0)
- pos = 0;
- else
- pos = myx / 32;
- pos += (ourcolor == WHITE) ? 16 : 0;
- if (captured[pos] == 0) {
- if (myx % 32 < 16)
- pos--;
- else
- pos++;
- if (pos < 0)
- return;
- if (captured[pos] == 0)
- return;
- }
- move = 1;
- deltax = x - (pos%16)*32;
- deltay = y-TOPSPACE;
- if (ourcolor == WHITE || reverse)
- deltay -= 64*8;
- else
- deltay += 64;
- shadow = pieces_icons[captured[pos]];
- frompos = -pos;
- realmove = FALSE;
- goto done;
- }
- if ((occupant[pos] == 0 || whose[pos] == theircolor) && ghost[pos] == 0)
- return;
- if (whose[pos] == ourcolor) {
- if (color != ourcolor) {
- message("It's not your turn!", TOMOVE);
- return;
- } else if (drawok[theircolor]) {
- message("Respond with 'y' or 'n'", TOMOVE);
- return;
- } else
- realmove = TRUE;
- } else
- realmove = FALSE; /* ghost */
- move = 1;
- frompos = pos;
- if (reverse) {
- deltax = x - (8-pos%10)*64;
- deltay = y-TOPSPACE - (8-pos/10)*64;
- } else {
- deltax = x - (pos%10-1)*64;
- deltay = y-TOPSPACE - (pos/10-1)*64;
- }
- /* Do sanity checking here! */
- if (ghost[pos])
- shadow = pieces_icons[ghost[pos]];
- else
- shadow = pieces_icons[occupant[pos]];
- done:
- XPixmapPut(window, 0, 0, x-deltax, y-deltay, 64, 64, shadow, GXxor, 1);
- }
-
- stopmove(pos, x, y)
- {
- bool *arr;
- int ox, oy;
-
- if (move == 0)
- return;
- move = 0;
- /* Remove shadow */
- XPixmapPut(window, 0, 0, x - deltax, y - deltay, 64, 64, shadow, GXxor, 1);
-
- if (pos < 0) /* out of window */
- return;
- if (pos == frompos)
- return; /* didn't move anywhere */
-
- /* Check if opponent resigned while we were in the process of moving. */
- if (dead || resign || (drawok[BLACK] && drawok[WHITE]))
- return;
- if (realmove == FALSE) { /* move a ghost */
- if (frompos <= 0) {
- frompos = -frompos;
- arr = captured;
- if (whose[pos] == OFFBOARD)
- return; /* it didn't go anywhere */
- } else
- arr = ghost;
- if (whose[pos] == ourcolor || ghost[pos])
- return; /* A ghost can't capture. */
- if (arr == ghost)
- redraw_pos(frompos);
- else {
- ox = (frompos % 16) * 32;
- if (reverse)
- oy = TOPSPACE + ((frompos>15) ? -64 : 64*8);
- else
- oy = TOPSPACE + ((frompos>15) ? 64*8 : -64);
- XPixmapPut(window, 0, 0, ox, oy, 64, 64, shadow, GXandInverted, 1);
- }
- if (whose[pos] == OFFBOARD) {
- ghost_capture(frompos);
- ghost[frompos] = 0;
- return;
- }
- ghost[pos] = arr[frompos];
- arr[frompos] = 0;
- redraw_ghost(pos);
- return;
- }
- if (whose[pos] == OFFBOARD) {
- return;
- }
- domove(frompos, pos);
-
- }
-
- piecemove(oldx, oldy, x, y)
- {
-
- XPixmapPut(window, 0, 0, oldx-deltax,oldy-deltay,
- 64, 64, shadow, GXxor, 1);
- XPixmapPut(window, 0, 0, x - deltax, y - deltay,
- 64, 64, shadow, GXxor, 1);
- }
-